﻿using FaceCat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices.JavaScript;
using System.Globalization;
using Blazor.Extensions.Canvas.Canvas2D;
using Blazor.Extensions.Canvas.Model;

namespace FaceCat
{
    public class BlazorPaint:FCPaint
    {
        /// <summary>
        /// 上下文
        /// </summary>
        public Canvas2DContext m_context;

        public bool m_hasClip;

        /// <summary>
        /// 横向偏移
        /// </summary>
        public int m_offsetX;

        /// <summary>
        /// 纵向偏移
        /// </summary>
        public int m_offsetY;

        /// <summary>
        /// 透明度
        /// </summary>
        public float m_opacity = 1;

        /// <summary>
        /// 资源路径
        /// </summary>
        public String m_resourcePath;

        /// <summary>
        /// 横向缩放因子
        /// </summary>
        public double m_scaleFactorX = 1;

        /// <summary>
        /// 纵向缩放因子
        /// </summary>
        public double m_scaleFactorY = 1;

        public MyColor m_myColor = new MyColor();

        /// <summary>
        /// 添加曲线
        /// </summary>
        /// <param name="rect">矩形区域</param>
        /// <param name="startAngle">从 x 轴到弧线的起始点沿顺时针方向度量的角（以度为单位）</param>
        /// <param name="sweepAngle">从 startAngle 参数到弧线的结束点沿顺时针方向度量的角（以度为单位）</param>
        public override void addArc(FCRect rect, float startAngle, float sweepAngle)
        {
        }

        /// <summary>
        /// 添加贝赛尔曲线
        /// </summary>
        /// <param name="points">点阵</param>
        public override void addBezier(FCPoint[] points)
        {

        }

        /// <summary>
        /// 添加曲线
        /// </summary>
        /// <param name="points">点阵</param>
        public override void addCurve(FCPoint[] points)
        {

        }

        /// <summary>
        /// 添加椭圆
        /// </summary>
        /// <param name="rect">矩形</param>
        public override void addEllipse(FCRect rect)
        {

        }

        /// <summary>
        /// 添加直线
        /// </summary>
        /// <param name="x1">第一个点的横坐标</param>
        /// <param name="y1">第一个点的纵坐标</param>
        /// <param name="x2">第二个点的横坐标</param>
        /// <param name="y2">第二个点的纵坐标</param>
        public override void addLine(int x1, int y1, int x2, int y2)
        {

        }

        /// <summary>
        /// 添加矩形
        /// </summary>
        /// <param name="rect">区域</param>
        public override void addRect(FCRect rect)
        {

        }

        /// <summary>
        /// 添加扇形
        /// </summary>
        /// <param name="rect">矩形区域</param>
        /// <param name="startAngle">从 x 轴到弧线的起始点沿顺时针方向度量的角（以度为单位）</param>
        /// <param name="sweepAngle">从 startAngle 参数到弧线的结束点沿顺时针方向度量的角（以度为单位）</param>
        public override void addPie(FCRect rect, float startAngle, float sweepAngle)
        {

        }

        /// <summary>
        /// 添加文字
        /// </summary>
        /// <param name="text">文字</param>
        /// <param name="font">字体</param>
        /// <param name="rect">区域</param>
        public override void addText(String text, FCFont font, FCRect rect, int width)
        {

        }

        /// <summary>
        /// 开始导出
        /// </summary>
        /// <param name="exportPath">路径</param>
        /// <param name="rect">区域</param>
        public override void beginExport(String exportPath, FCRect rect)
        {
        }

        /// <summary>
        /// 开始绘图
        /// </summary>
        public override void beginPaint(IntPtr hdc, FCRect wRect, FCRect pRect)
        {
            m_offsetX = 0;
            m_offsetY = 0;
        }

        /// <summary>
        /// 开始一段路径
        /// </summary>
        public override void beginPath()
        {
        }

        /// <summary>
        /// 清除缓存
        /// </summary>
        public override void clearCaches()
        {
        }

        /// <summary>
        /// 裁剪路径
        /// </summary>
        public override void clipPath()
        {
        }

        /// <summary>
        /// 闭合路径
        /// </summary>
        public override void closeFigure()
        {
        }

        /// <summary>
        /// 结束一段路径
        /// </summary>
        public override void closePath()
        {
        }

        /// <summary>
        /// 销毁对象
        /// </summary>
        public override void delete()
        {
            clearCaches();
        }

        /// <summary>
        /// 绘制弧线
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="rect">矩形区域</param>
        /// <param name="startAngle">从 x 轴到弧线的起始点沿顺时针方向度量的角（以度为单位）</param>
        /// <param name="sweepAngle">从 startAngle 参数到弧线的结束点沿顺时针方向度量的角（以度为单位）</param>
        public override void drawArc(long dwPenColor, float width, int style, FCRect rect, float startAngle, float sweepAngle)
        {
        }

        /// <summary>
        /// 设置贝赛尔曲线
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="points">坐标阵1</param>
        public override void drawBezier(long dwPenColor, float width, int style, FCPoint[] points)
        {
        }

        /// <summary>
        /// 绘制曲线
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="points">坐标阵</param>
        public override void drawCurve(long dwPenColor, float width, int style, FCPoint[] points)
        {
        }

        /// <summary>
        /// 绘制矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="rect">矩形区域</param>
        public override void drawEllipse(long dwPenColor, float width, int style, FCRect rect)
        {
            drawRect(dwPenColor, width, style, rect);
        }

        /// <summary>
        /// 绘制图片
        /// </summary>
        /// <param name="imagePath">图片路径</param>
        /// <param name="rect">绘制区域</param>
        public override void drawImage(String imagePath, FCRect rect)
        {
        }

        /// <summary>
        /// 绘制矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="left">左侧坐标</param>
        /// <param name="top">顶部左标</param>
        /// <param name="right">右侧坐标</param>
        /// <param name="bottom">底部坐标</param>
        public override void drawEllipse(long dwPenColor, float width, int style, int left, int top, int right, int bottom)
        {
            FCRect rect = new FCRect(left, top, right, bottom);
            drawEllipse(dwPenColor, width, style, rect);
        }

        /// <summary>
        /// 绘制直线
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="x1">第一个点的横坐标</param>
        /// <param name="y1">第一个点的纵坐标</param>
        /// <param name="x2">第二个点的横坐标</param>
        /// <param name="y2">第二个点的纵坐标</param>
        public override void drawLine(long dwPenColor, float width, int style, int x1, int y1, int x2, int y2)
        {
            if (dwPenColor == FCColor.None) return;
            int lx1 = x1 + m_offsetX;
            int ly1 = y1 + m_offsetY;
            int lx2 = x2 + m_offsetX;
            int ly2 = y2 + m_offsetY;
            if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
            {
                lx1 = (int)(m_scaleFactorX * lx1);
                ly1 = (int)(m_scaleFactorY * ly1);
                lx2 = (int)(m_scaleFactorX * lx2);
                ly2 = (int)(m_scaleFactorY * ly2);
            }
            m_context.BeginPathAsync();
            m_context.SetStrokeStyleAsync(getDrawColor(dwPenColor));
            float lineWidth = (float)(width * Math.Min(m_scaleFactorX, m_scaleFactorY));
            m_context.SetLineWidthAsync(lineWidth);
            m_context.MoveToAsync(lx1, ly1);
            m_context.LineToAsync(lx2, ly2);
            m_context.StrokeAsync();
        }

        /// <summary>
        /// 绘制直线
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="x">第一个点的坐标</param>
        /// <param name="y">第二个点的坐标</param>
        public override void drawLine(long dwPenColor, float width, int style, FCPoint x, FCPoint y)
        {
            drawLine(dwPenColor, width, style, x.x, x.y, y.x, y.y);
        }

        /// <summary>
        /// 绘制路径
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        public override void drawPath(long dwPenColor, float width, int style)
        {
        }

        /// <summary>
        /// 绘制扇形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="rect">矩形区域</param>
        /// <param name="startAngle">从 x 轴到弧线的起始点沿顺时针方向度量的角（以度为单位）</param>
        /// <param name="sweepAngle">从 startAngle 参数到弧线的结束点沿顺时针方向度量的角（以度为单位）</param>
        public override void drawPie(long dwPenColor, float width, int style, FCRect rect, float startAngle, float sweepAngle)
        {
        }

        /// <summary>
        /// 绘制多边形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="points">点的数组</param>
        public override void drawPolygon(long dwPenColor, float width, int style, FCPoint[] points)
        {
        }

        /// <summary>
        /// 绘制大量直线
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="points">点集</param>
        public override void drawPolyline(long dwPenColor, float width, int style, FCPoint[] points)
        {
            if (dwPenColor == FCColor.None) return;
            m_context.BeginPathAsync();
            m_context.SetStrokeStyleAsync(getDrawColor(dwPenColor));
            float lineWidth = (float)(width * Math.Min(m_scaleFactorX, m_scaleFactorY));
            m_context.SetLineWidthAsync(lineWidth);
            for (int i = 0; i < points.Length; i++)
            {
                int x = points[i].x + m_offsetX;
                int y = points[i].y + m_offsetY;
                if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
                {
                    x = (int)(m_scaleFactorX * x);
                    y = (int)(m_scaleFactorY * y);
                }
                if (i == 0)
                {
                    m_context.MoveToAsync(x, y);
                }
                else
                {
                    m_context.LineToAsync(x, y);
                }
            }
            m_context.StrokeAsync();
        }

        /// <summary>
        /// 绘制矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="rect">矩形区域</param>
        public override void drawRect(long dwPenColor, float width, int style, FCRect rect)
        {
            if (dwPenColor == FCColor.None) return;
            int w = rect.right - rect.left - 1;
            if (w < 1) w = 1;
            int h = rect.bottom - rect.top - 1;
            if (h < 1) h = 1;
            m_context.SetStrokeStyleAsync(getDrawColor(dwPenColor));
            float lineWidth = (float)(width * Math.Min(m_scaleFactorX, m_scaleFactorY));
            m_context.SetLineWidthAsync(lineWidth);
            m_context.StrokeRectAsync((rect.left + this.m_offsetX) * this.m_scaleFactorX, (rect.top + this.m_offsetY) * this.m_scaleFactorY, w * this.m_scaleFactorX, h * m_scaleFactorY);
        }

        /// <summary>
        /// 绘制矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="left">左侧坐标</param>
        /// <param name="top">顶部左标</param>
        /// <param name="right">右侧坐标</param>
        /// <param name="bottom">底部坐标</param>
        public override void drawRect(long dwPenColor, float width, int style, int left, int top, int right, int bottom)
        {
            FCRect rect = new FCRect(left, top, right, bottom);
            drawRect(dwPenColor, width, style, rect);
        }

        /// <summary>
        /// 绘制文字
        /// </summary>
        /// <param name="text">文字</param>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="font">字体</param>
        /// <param name="rect">矩形区域</param>
        public override void drawText(String text, long dwPenColor, FCFont font, FCRect rect, int width)
        {
            if (dwPenColor == FCColor.None) return;
            FCSize tSize = textSize(text, font);
            int rw = tSize.cx;
            int rh = tSize.cy;
            float rate = (float)(m_scaleFactorX + m_scaleFactorY) / 2;
            String fontFamily = font.m_fontFamily;
            if (fontFamily == "Default")
            {
                fontFamily = MyColor.getSystemFont();
            }
            int tx = (int)((rect.left + m_offsetX) * this.m_scaleFactorX);
            int ty = (int)((rect.top + m_offsetY) * this.m_scaleFactorY);
            m_context.SetTextAlignAsync(TextAlign.Left);
            m_context.SetTextBaselineAsync(TextBaseline.Top);
            m_context.SetFillStyleAsync(getDrawColor(dwPenColor));
            m_context.FillTextAsync(text, tx, ty);
        }

        /// <summary>
        /// 绘制文字
        /// </summary>
        /// <param name="text">文字</param>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="font">字体</param>
        /// <param name="rect">矩形区域</param>
        public override void drawText(String text, long dwPenColor, FCFont font, FCRectF rect, int width)
        {
            drawText(text, dwPenColor, font, new FCRect(rect.left, rect.top, rect.right, rect.bottom), width);
        }

        /// <summary>
        /// 绘制圆角矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="width">宽度</param>
        /// <param name="style">样式</param>
        /// <param name="rect">矩形区域</param>
        /// <param name="cornerRadius">边角半径</param>
        public override void drawRoundRect(long dwPenColor, float width, int style, FCRect rect, int cornerRadius)
        {
            drawRect(dwPenColor, width, style, rect);
        }

        /// <summary>
        /// 绘制自动省略结尾的文字
        /// </summary>
        /// <param name="text">文字</param>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="font">字体</param>
        /// <param name="rect">矩形区域</param>
        public override void drawTextAutoEllipsis(String text, long dwPenColor, FCFont font, FCRect rect)
        {
            drawText(text, dwPenColor, font, rect);
        }

        /// <summary>
        /// 结束绘图
        /// </summary>
        public override void endPaint()
        {
            m_hasClip = false;
        }

        /// <summary>
        /// 填充椭圆
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="rect">矩形区域</param>
        public override void fillEllipse(long dwPenColor, FCRect rect)
        {
            fillEllipse(dwPenColor, rect.left, rect.top, rect.right, rect.bottom);
        }

        /// <summary>
        /// 填充椭圆
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="left">左侧坐标</param>
        /// <param name="top">顶部左标</param>
        /// <param name="right">右侧坐标</param>
        /// <param name="bottom">底部坐标</param>
        public override void fillEllipse(long dwPenColor, int left, int top, int right, int bottom)
        {
            fillRect(dwPenColor, left, top, right, bottom);
        }

        /// <summary>
        /// 绘制渐变椭圆
        /// </summary>
        /// <param name="dwFirst">开始颜色</param>
        /// <param name="dwSecond">结束颜色</param>
        /// <param name="rect">矩形</param>
        /// <param name="angle">角度</param>
        public override void fillGradientEllipse(long dwFirst, long dwSecond, FCRect rect, int angle)
        {
            fillEllipse(dwFirst, rect);
        }

        /// <summary>
        /// 填充渐变路径
        /// </summary>
        /// <param name="dwFirst">开始颜色</param>
        /// <param name="dwSecond">结束颜色</param>
        /// <param name="points">点的集合</param>
        /// <param name="angle">角度</param>
        public override void fillGradientPath(long dwFirst, long dwSecond, FCRect rect, int angle)
        {
            fillPath(dwFirst);
        }

        /// <summary>
        /// 绘制渐变的多边形
        /// </summary>
        /// <param name="dwFirst">开始颜色</param>
        /// <param name="dwSecond">结束颜色</param>
        /// <param name="rect">点的集合</param>
        /// <param name="angle">角度</param>
        public override void fillGradientPolygon(long dwFirst, long dwSecond, FCPoint[] points, int angle)
        {
            fillPolygon(dwFirst, points);
        }

        /// <summary>
        /// 绘制渐变矩形
        /// </summary>
        /// <param name="dwFirst">开始颜色</param>
        /// <param name="dwSecond">结束颜色</param>
        /// <param name="rect">矩形</param>
        /// <param name="cornerRadius">边角半径</param>
        /// <param name="angle">角度</param>
        public override void fillGradientRect(long dwFirst, long dwSecond, FCRect rect, int cornerRadius, int angle)
        {
            fillRect(dwFirst, rect);
        }

        /// <summary>
        /// 填充路径
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        public override void fillPath(long dwPenColor)
        {
        }

        /// <summary>
        /// 绘制扇形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="rect">矩形区域</param>
        /// <param name="startAngle">从 x 轴到弧线的起始点沿顺时针方向度量的角（以度为单位）</param>
        /// <param name="sweepAngle">从 startAngle 参数到弧线的结束点沿顺时针方向度量的角（以度为单位）</param>
        public override void fillPie(long dwPenColor, FCRect rect, float startAngle, float sweepAngle)
        {
        }

        /// <summary>
        /// 填充矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="left">左侧坐标</param>
        /// <param name="top">顶部左标</param>
        /// <param name="right">右侧坐标</param>
        /// <param name="bottom">底部坐标</param>
        public override void fillRect(long dwPenColor, int left, int top, int right, int bottom)
        {
            if (dwPenColor == FCColor.None) return;
            int w = right - left;
            if (w < 1) w = 1;
            int h = bottom - top;
            if (h < 1) h = 1;
            m_context.SetFillStyleAsync(getDrawColor(dwPenColor));
            m_context.FillRectAsync((left + this.m_offsetX) * this.m_scaleFactorX, (top + this.m_offsetY) * this.m_scaleFactorY, w * this.m_scaleFactorX, h * m_scaleFactorY);
        }

        /// <summary>
        /// 填充矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="rect">矩形区域</param>
        public override void fillRect(long dwPenColor, FCRect rect)
        {
            fillRect(dwPenColor, rect.left, rect.top, rect.right, rect.bottom);
        }

        /// <summary>
        /// 填充多边形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="points">点的数组</param>
        public override void fillPolygon(long dwPenColor, FCPoint[] points)
        {
        }

        /// <summary>
        /// 填充圆角矩形
        /// </summary>
        /// <param name="dwPenColor">颜色</param>
        /// <param name="rect">矩形区域</param>
        /// <param name="cornerRadius">边角半径</param>
        public override void fillRoundRect(long dwPenColor, FCRect rect, int cornerRadius)
        {
            fillRect(dwPenColor, rect.left, rect.top, rect.right, rect.bottom);
        }

        /// <summary>
        /// 反裁剪路径
        /// </summary>
        public override void excludeClipPath()
        {
        }

        /// <summary>
        /// 设置裁剪区域
        /// </summary>
        /// <param name="rect">区域</param>
        public virtual void excludeClip(FCRect rect)
        {
        }

        /// <summary>
        /// 获取颜色
        /// </summary>
        /// <param name="dwPenColor">输入颜色</param>
        /// <returns>输出颜色</returns>
        public override long getColor(long dwPenColor)
        {
            long color = dwPenColor;
            if (dwPenColor < FCColor.None)
            {
                color = m_myColor.getUserColor(dwPenColor);
            }
            return color;
        }

        /// <summary>
        /// 获取要绘制的颜色
        /// </summary>
        /// <param name="dwPenColor"></param>
        /// <returns></returns>
        public String getDrawColor(long dwPenColor)
        {
            long color = getPaintColor(dwPenColor);
            int a = 0, r = 0, g = 0, b = 0;
            FCColor.toRgba(null, color, ref r, ref g, ref b, ref a);
            String str = String.Empty;
            if (a == 255)
            {
                str = String.Format("rgb({0},{1},{2})", r, g, b);
            }
            else
            {
                str = String.Format("rgba({0},{1},{2},{3})", r, g, b, (double)a / 255);
            }
            return str;
        }

        /// <summary>
        /// 获取要绘制的颜色
        /// </summary>
        /// <param name="dwPenColor">输入颜色</param>
        /// <returns>输出颜色</returns>
        public override long getPaintColor(long dwPenColor)
        {
            return getColor(dwPenColor);
        }

        /// <summary>
        /// 获取偏移
        /// </summary>
        /// <returns>偏移坐标</returns>
        public override FCPoint getOffset()
        {
            return new FCPoint(m_offsetX, m_offsetY);
        }

        /// <summary>
        /// 获取缩放比例
        /// </summary>
        /// <param name="scaleFactorX">横向缩放比例</param>
        /// <param name="scaleFactorY">纵向缩放比例</param>
        public override void getScaleFactor(ref double scaleFactorX, ref double scaleFactorY)
        {
            scaleFactorX = m_scaleFactorX;
            scaleFactorY = m_scaleFactorY;
        }

        /// <summary>
        /// 旋转角度
        /// </summary>
        /// <param name="op">圆心坐标</param>
        /// <param name="mp">点的坐标</param>
        /// <param name="angle">角度</param>
        /// <returns>结果坐标</returns>
        public override FCPoint rotate(FCPoint op, FCPoint mp, int angle)
        {
            float PI = 3.14159265f;
            FCPoint pt = new FCPoint();
            pt.x = (int)((mp.x - op.x) * Math.Cos(angle * PI / 180) - (mp.y - op.y) * Math.Sin(angle * PI / 180) + op.x);
            pt.y = (int)((mp.x - op.x) * Math.Sin(angle * PI / 180) + (mp.y - op.y) * Math.Cos(angle * PI / 180) + op.y);
            return pt;
        }

        /// <summary>
        /// 设置裁剪区域
        /// </summary>
        /// <param name="rect">区域</param>
        public override void setClip(FCRect rect)
        {
            return;
            int w = rect.right - rect.left;
            int h = rect.bottom - rect.top;
            m_context.BeginPathAsync();
            m_context.RectAsync((rect.left + this.m_offsetX) * this.m_scaleFactorX, (rect.top + this.m_offsetY) * this.m_scaleFactorY, w * this.m_scaleFactorX, h * m_scaleFactorY);
            m_context.ClipAsync();
        }

        /// <summary>
        /// 设置偏移
        /// </summary>
        /// <param name="mp">偏移坐标</param>
        public override void setOffset(FCPoint mp)
        {
            m_offsetX = mp.x;
            m_offsetY = mp.y;
        }

        /// <summary>
        /// 设置透明度
        /// </summary>
        /// <param name="opacity">透明度</param>
        public override void setOpacity(float opacity)
        {
            if (m_opacity != opacity)
            {
                m_opacity = opacity;
            }
        }

        /// <summary>
        /// 设置缩放因子
        /// </summary>
        /// <param name="scaleFactorX">横向因子</param>
        /// <param name="scaleFactorY">纵向因子</param>
        public override void setScaleFactor(double scaleFactorX, double scaleFactorY)
        {
            m_scaleFactorX = scaleFactorX;
            m_scaleFactorY = scaleFactorY;
        }

        /// <summary>
        /// 设置资源的路径
        /// </summary>
        /// <param name="resourcePath">资源的路径</param>
        public override void setResourcePath(String resourcePath)
        {
            m_resourcePath = resourcePath;
        }

        /// <summary>
        /// 设置是否支持透明色
        /// </summary>
        /// <returns>是否支持</returns>
        public override bool supportTransparent()
        {
            return true;
        }

        /// <summary>
        /// 获取文字大小
        /// </summary>
        /// <param name="text">文字</param>
        /// <param name="font">字体</param>z
        /// <returns>字体大小</returns>
        public override FCSize textSize(String text, FCFont font, int width)
        {
            FCSizeF sizeF = textSizeF(text, font, width);
            return new FCSize((int)sizeF.cx, (int)sizeF.cy);
        }

        /// <summary>
        /// 获取文字大小
        /// </summary>
        /// <param name="text">文字</param>
        /// <param name="font">字体</param>
        /// <returns>字体大小</returns>
        public override FCSizeF textSizeF(String text, FCFont font, int width)
        {
            return new FCSizeF(text.Length * 5, font.m_fontSize / 2);
            float rate = (float)(m_scaleFactorX + m_scaleFactorY) / 2;
            String fontFamily = font.m_fontFamily;
            if (fontFamily == "Default")
            {
                fontFamily = MyColor.getSystemFont();
            }
            String sFont = (font.m_fontSize * rate).ToString() + "px " + fontFamily;
            if (font.m_bold)
            {
                sFont += " bold";
            }
            if (font.m_italic)
            {
                sFont += " italic";
            }
            m_context.SetFontAsync(sFont);
            m_context.SetTextAlignAsync(TextAlign.Left);
            m_context.SetTextBaselineAsync(TextBaseline.Top);
            TextMetrics metrics = m_context.MeasureTextAsync(text).Result;
            double actualHeight = metrics.ActualBoundingBoxAscent + metrics.ActualBoundingBoxDescent;
            FCSizeF tSize = new FCSizeF((float)(metrics.Width) / rate, (float)(actualHeight / rate));
            return tSize;
        }
    }
}
